package com.blb.ssm.controller.base;

import com.blb.ssm.utils.ResponseEntity;

/**
 * 基础控制器
 * 
 * 存放Controller层中公共的方法
 * 存放Controller层中公共的常量
 * @author Administrator
 *
 */
public class BaseController {

	public static final String LOGIN = "login";
	public static final String INDEX = "index";
	public static final String ADMIN = "admin";
	public static final String FRONT = "front";
	public static final String MSG = "msg";
	
	public static final String USER = "user";
	
	/**
	 * 转发
	 * @param strs
	 * @return
	 */
	public String disPlay(String...strs){
		StringBuffer strb = new StringBuffer();
		for (String str : strs) {
			if (strb.length()!=0) strb.append("/");
			strb.append(str);
		}
		return strb.toString();
	}
	
	/**
	 * 重定向
	 * @param strs
	 * @return
	 */
	public String redirect(String...strs){
		StringBuffer strb = new StringBuffer();
		for (String str : strs) {
			if (strb.length()!=0) strb.append("/");
			strb.append(str);
		}
		return "redirect:/" + strb.toString();
	}
	
	/**
	 * 默认返回成功
	 * @return
	 */
	public ResponseEntity success(){
		return ResponseEntity.success();
	}
	
	/**
	 * 返回成功，自定义成功提示
	 * @param msg
	 * @return
	 */
	public ResponseEntity success(String msg){
		return ResponseEntity.success(msg);
	}
	
	/**
	 * 返回成功，自定义返回数据
	 * @param data
	 * @return
	 */
	public ResponseEntity success(Object data){
		return ResponseEntity.success(data);
	}
	
	/**
	 * 返回成功，自定义成功提示和数据
	 * @param msg
	 * @param data
	 * @return
	 */
	public ResponseEntity success(String msg, Object data){
		return ResponseEntity.success(msg, data);
	}
	
	/**
	 * 返回默认失败
	 * @return
	 */
	public ResponseEntity error(){
		return ResponseEntity.error();
	}
	
	/**
	 * 返回失败，自定义失败提示
	 * @param msg
	 * @return
	 */
	public ResponseEntity error(String msg){
		return ResponseEntity.error(msg);
	}
	
	/**
	 * 返回失败，自定义失败数据
	 * @param data
	 * @return
	 */
	public ResponseEntity error(Object data){
		return ResponseEntity.error(data);
	}
	
	/**
	 * 返回失败，自定义失败提示和数据
	 * @param msg
	 * @param data
	 * @return
	 */
	public ResponseEntity error(String msg, Object data){
		return ResponseEntity.error(msg, data);
	}
}
